#include "I18n.h"
#include <boost/thread/tss.hpp>

#define PHNQLETS_DEFAULT_LOCALE "en"

namespace phnq
{
	namespace phnqlets
	{
		static boost::thread_specific_ptr<string> currentLocale;

		I18n::I18n()
		{
			// a little constructor action
		}

		I18n::~I18n()
		{
			// a little destructor action
		}
		
		void I18n::setCurrentLocale(string locale)
		{
			currentLocale.reset(new string(locale));
		}
		
		string I18n::getCurrentLocale()
		{
			string *locale = currentLocale.get();
			
			if(locale)
				return *locale;
			else
				return PHNQLETS_DEFAULT_LOCALE;
		}
		
		void I18n::unsetCurrentLocale()
		{
			string *locale = currentLocale.get();
			if(locale)
				currentLocale.release();
		}
		
		string I18n::getL10nPath(string path)
		{
			size_t slashIdx = path.find_first_of("/");
			if(slashIdx != string::npos)
			{
				string c0 = path.substr(0, slashIdx);
				if(c0 == "i18n")
					path = "i18n/" + getCurrentLocale() + path.substr(slashIdx);
			}
			return path;
		}
	}
}
